<template>
    <div :class="`goods-list-item ${mode} ${styleMode}`" @click="gotoDetail">
        <div class="goods-img">
            <img class="img-value" :src="imageSrc" alt="">
        </div>
        <div class="goods-detail">
            <div class="goods-name title-color">{{itemInfo.name}}</div>
            <div class="goods-info">
                <div class="goods-price" :style="fontColor">
                    <span class="label">￥</span>{{itemInfo.price_range[0] / 100}}
                    <span v-if="itemInfo.price_range.length > 1" class="is-up">起</span>
                </div>
                <div class="goods-action" @click.stop="addToBag">
                    <MiniIcon name="addbag" :mode="mode" :styleMode="styleMode" :theme="theme" />
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { mapActions } from 'vuex';
import { MiniIcon } from '@components/base';
import { redirectTo, createShopImageSrc } from '@common/utils';
import { getShopGoodsPrice } from '@biztools/shop';
import ModeMixin from '@common/mixin';
import { TipError } from '@common/tip';
export default {
    name: 'GoodsListItem', // 列表项
    mixins: [ModeMixin],
    components: {
        MiniIcon,
    },
    props: {
        shopInfo: {
            type: Object,
            default: () => {},
        },
        itemInfo: {
            type: Object,
            default() {
                return {};
            },
        },
        isBrand: {
            type: Boolean,
            default: true,
        },
    },
    computed: {
        itemPrice() {
            const { itemInfo } = this.$props;
            return getShopGoodsPrice(itemInfo);
        },
        imageSrc() {
            const { itemInfo } = this.$props;
            return createShopImageSrc(itemInfo.title_pic);
        },
    },
    methods: {
        ...mapActions([
            'setGoodsDetailInfo',
            'setSpecialShopInfo',
        ]),
        gotoDetail() {
            const { isBrand } = this.$props;
            if (isBrand) {
                this.setSpecialShopInfo(null);
            }
            this.setGoodsDetailInfo(this.$props.itemInfo);
            redirectTo(`shop/detail/${this.$props.itemInfo.id}`);
        },
        addToBag() {
            const { itemInfo } = this.$props;
            if (itemInfo.status === 0) {
                TipError('商品已下架');
                return;
            }
            this.$emit('addToBag', this.$props.itemInfo);
        },
    },
};
</script>

<style lang="less">
@goods-item-img-bg: #E7E8E7;
.goods-list-item {
    background-color: @white;
    .mode-white();
    height: 250px;
    .m-b(@shop-gap-md);
    overflow: hidden;
    // box-shadow: 0 4px 16px -4px rgba(51,51,51,0.06);
    border: 0.5px solid rgba(0, 0, 0, 0.04);
    &.circle {
        border-radius: @shop-border-radius-md;
    }
    .goods-img {
        height: 165px;
        background-color: @goods-item-img-bg;
        width: 100%;
        overflow: hidden;
        .flex-row-center();
        .img-value {
            width: 100%;
            height: 100%;
        }
    }
    .goods-detail {
        .p-h(12);
        .p-t(@shop-gap);
        .goods-name {
            .text-overflow-line(2);
            font-size: @font-size;
            line-height: 17px;
            height: 34px;
            .m-b(@shop-gap);
            color: @text-color;
        }
        .goods-info {
            .flex-row-between();
            .goods-price {
                .flex();
                font-size: @font-size-lg;
                align-items: baseline;
                color: @shop-price-color;
                font-family: @font-family-number;
                font-weight: 500;
                .label {
                    .m-r(-3);
                }
                .is-up {
                    font-size: @shop-font-size-sm;
                }
            }
        }
    }
}
</style>
